package com.secf.service.port.hpy.hys.test.day5;

/**
 * @Author luoYong
 * @Date 2024-08-13 17:40
 */
public class GameCoordinateManager {
    public static void main(String[] args) {
        int[][] coordinates = {
                {10, 20},
                {30, 40},
                {50, 60}
        };

        updateCoordinate(coordinates, 1, 35, 45);
        System.out.println("Updated Coordinates: " + arrayToString(coordinates));

        int[] coord = getCoordinate(coordinates, 2);
        System.out.println("Coordinate of object 3: (" + coord[0] + ", " + coord[1] + ")");
    }

    public static void updateCoordinate(int[][] coordinates, int index, int x, int y) {
        if (index >= 0 && index < coordinates.length) {
            coordinates[index][0] = x;
            coordinates[index][1] = y;
        }
    }

    public static int[] getCoordinate(int[][] coordinates, int index) {
        if (index >= 0 && index < coordinates.length) {
            return coordinates[index];
        }
        return null;
    }

    public static String arrayToString(int[][] array) {
        StringBuilder sb = new StringBuilder();
        for (int[] row : array) {
            sb.append("(").append(row[0]).append(", ").append(row[1]).append(") ");
        }
        return sb.toString().trim();
    }
}
